/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.config.javabeans;

import java.io.Serializable;


/**
 * Class correspoding to the "profile" element of profiles_config.xml.<br>
 * This is the definition of a profile (a group of users sharing some properties).<br>
 *
 * Available profile types are :<br>
 *
 *  <li>dynamicgroup: dynamic group, in this case group dname is given</li>
 *  <li>staticgroup: static group(s), in this case either group dname or
 *  filter to get groups is given</li>
 *  <li>filter: groups defined by a filter, in this case filter and base are given</li>
 *  <li>user: single user profile, in this case the user dname is given</li>
 *  <li>default: profile used in case no other profile matches.</li>
 *
 */
public class JBProfile implements Serializable
{
    /** Dynamic group typed profile. */
    public static final String TYPE_DYNAMIC_GROUP = "dynamicgroup";

    /** Static group(s) typed profile. */
    public static final String TYPE_STATIC_GROUP = "staticgroup";

    /** Filter typed profile. */
    public static final String TYPE_FILTER = "filter";

    /**  Single user toed profile. */
    public static final String TYPE_USER = "user";

    /** Default typed profile. */
    public static final String TYPE_DEFAULT = "default";

    /** Profile type. */
    private String type;

    /** Profile name. */
    private String name;

    /** LDAP base dname, for filter profiles. */
    private String base;

    /** LDAP filter, for filter or staticgroup profiles. */
    private String filter;

    /** dname, for dynamicgroup or staticgroup os user profiles. */
    private String dn;

    /** Resources associated with the profile. */
    private JBRessources jbRessources = new JBRessources();

    /** Creates new JBProfile. */
    public JBProfile()
    {
    }

    /**
     * Returns the LDAP base dname, for filter profiles.
     * @return dname
     */
    public String getBase()
    {
        return base;
    }

    /**
     * Returns the dname, for dynamicgroup or staticgroup os user profiles.
     * @return dname
     */
    public String getDn()
    {
        return dn;
    }

    /**
     * Returns the LDAP filter, for filter or staticgroup profiles..
     * @return filter
     */
    public String getFilter()
    {
        return filter;
    }

    /**
     * Returns the resources associated with the profile.
     * @return resources
     */
    public JBRessources getJbRessources()
    {
        return jbRessources;
    }

    /**
     * Returns the profile name.
     * @return name
     */
    public String getName()
    {
        return name;
    }

    /**
     * Returns the profile type.
     * @return type
     */
    public String getType()
    {
        return type;
    }

    /**
     * Sets the the LDAP base dname, for filter profiles.
     * @param abase The base to set
     */
    public void setBase(String abase)
    {
        this.base = abase;
    }

    /**
     * Sets the the dname, for dynamicgroup or staticgroup os user profiles.
     * @param adn The dname to set
     */
    public void setDn(String adn)
    {
        this.dn = adn;
    }

    /**
     * Sets the LDAP filter, for filter or staticgroup profiles.
     * @param afilter The filter to set
     */
    public void setFilter(String afilter)
    {
        this.filter = afilter;
    }

    /**
     * Sets the the resources associated with the profile.
     * @param ajbRessources The resources to set
     */
    public void setJbRessources(JBRessources ajbRessources)
    {
        this.jbRessources = ajbRessources;
    }

    /**
     * Sets the profile name.
     * @param aname The name to set
     */
    public void setName(String aname)
    {
        this.name = aname;
    }

    /**
     * Sets the profile type.
     * @param atype The type to set
     */
    public void setType(String atype)
    {
        this.type = atype;
    }

    /**
     * Displays the profile definition.
     *
     * @return profile definition.
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        buf.append("type = ");
        buf.append(type);
        buf.append(System.getProperty("line.separator"));
        buf.append("name = ");
        buf.append(name);
        buf.append(System.getProperty("line.separator"));
        buf.append("base = ");
        buf.append(base);
        buf.append(System.getProperty("line.separator"));
        buf.append("filter = ");
        buf.append(filter);
        buf.append(System.getProperty("line.separator"));
        buf.append("dn = ");
        buf.append(dn);
        buf.append(System.getProperty("line.separator"));
        buf.append("jbRessources = ");
        buf.append(jbRessources);
        buf.append(System.getProperty("line.separator"));

        return buf.toString();
    }

    /**
     * Checks whether the profile is a dynamic group typed profile.
     *
     * @return true if it is, false if it is not.
     */
    public boolean isTypeDynamicGroup()
    {
        return (this.getType().compareToIgnoreCase(TYPE_DYNAMIC_GROUP) == 0);
    }

    /**
     * Checks whether the profile is a static group typed profile.
     *
     * @return true if it is, false if it is not.
     */
    public boolean isTypeStaticGroup()
    {
        return (this.getType().compareToIgnoreCase(TYPE_STATIC_GROUP) == 0);
    }

    /**
     * Checks whether the profile is a filter typed profile.
     *
     * @return true if it is, false if it is not.
     */
    public boolean isTypeFilter()
    {
        return (this.getType().compareToIgnoreCase(TYPE_FILTER) == 0);
    }

    /**
     * Checks whether the profile is a single user typed profile.
     *
     * @return true if it is, false if it is not.
     */
    public boolean isTypeUser()
    {
        return (this.getType().compareToIgnoreCase(TYPE_USER) == 0);
    }
}
